package com.ah.shanxi_demo.convert;

import com.ah.shanxi_demo.common.enums.OrderCommonEnum;
import com.ah.shanxi_demo.common.enums.PolicyDeleteEnum;
import com.ah.shanxi_demo.entity.SxOrder;
import com.ah.shanxi_demo.entity.SxOrderReceipt;
import com.ah.shanxi_demo.param.result.OrderRO;
import com.ah.shanxi_demo.param.result.OrderShowRO;
import com.ah.shanxi_demo.sync.param.result.SyncOrderResult;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zt 2020/8/24
 */
public class ConvertOrder {


    /**
     * 工单列表转换
     *
     * @param sxOrderList
     * @return
     */
    public static List<OrderRO> convert_order_ro_list(List<SxOrder> sxOrderList) {
        List<OrderRO> list = new ArrayList<>();

        if (CollectionUtils.isEmpty(sxOrderList)) {
            return new ArrayList<>();
        }
        sxOrderList.stream().forEach(sxOrder -> {
            list.add(convert_order_ro(sxOrder));
        });
        return list;
    }


    /**
     * 工单转换
     *
     * @param sxOrder
     * @return
     */
    public static OrderRO convert_order_ro(SxOrder sxOrder) {

        OrderRO model = new OrderRO();
        BeanUtils.copyProperties(model, sxOrder);

        return model;
    }




    /**
     * 部级平台返回工单数据 转换为表数据格式
     *
     * @param syncOrderResultList
     * @return
     */
    public static List<SxOrder> convert_order_list(List<SyncOrderResult> syncOrderResultList, Long registerId) {

        List<SxOrder> sxOrderList=new ArrayList<>();

        syncOrderResultList.stream().forEach(p -> {

            SxOrder sxOrder=new SxOrder();
            sxOrder.setRegisterId(registerId);
            sxOrder.setDelete(PolicyDeleteEnum.UN_DELETE.getKeyInt());
            sxOrder.setOrderStatus(OrderCommonEnum.STATUS_INIT.getKeyInt());

            p.getWork_list().stream().forEach(item->{

                sxOrder.setWorkCode(item.getWork_code());
                sxOrder.setTitle(item.getTitle());
                sxOrder.setContent(item.getContent());
                sxOrder.setAccdept(item.getAccdept());
                sxOrder.setAccuser(item.getAccuser());
                sxOrder.setWriteUser(item.getWrite_user());
                sxOrder.setType(item.getType());
                sxOrder.setLevel(item.getLevel());
                sxOrder.setScanType(item.getScan_type());

                sxOrderList.add(sxOrder);
            });
        });

        return sxOrderList;
    }

    /**
     * 工单查看转换
     *
     * @param sxOrder
     * @return
     */
    public static OrderShowRO merge_order_show_ro(SxOrder sxOrder, SxOrderReceipt sxOrderReceipt) {
        OrderShowRO model = new OrderShowRO();

        if (sxOrderReceipt!=null){
            model = convert_order_show_ro(sxOrderReceipt);
        }

        if (sxOrder!=null){
            OrderRO orderRO = convert_order_ro(sxOrder);
            model.setOrderModel(orderRO);
        }

        return model;
    }


    /**
     * 工单转换
     *
     * @param sxOrderReceipt
     * @return
     */
    public static OrderShowRO convert_order_show_ro(SxOrderReceipt sxOrderReceipt) {

        OrderShowRO model = new OrderShowRO();
        BeanUtils.copyProperties(model, sxOrderReceipt);

        return model;
    }


}
